package com.ruoyi.biz.api.service;

import com.ruoyi.common.utils.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;

/**
 * 策略模式代替多分支
 * author: 周周
 */
@Service
public class CommonQueryService {
    private final static String today = "本日";
    private final static String thisWeek = "本周";
    private final static String thisMouth = "本月";
    private final static String unLimited = "无限制";
    private final static String foreverLimit = "永久";
/*    @Resource
    private AchieveService achieveService;
    private final Map<String, Function<BizActivity, Boolean>> commonTypeMap = new HashMap<>();

    *//**
     *  初始化业务分派逻辑,代替了if-else部分
     *  value: lambda表达式
     *//*
    @PostConstruct
    public void dispatcherInit(){
        commonTypeMap.put(today, activity-> achieveService.judgeDay(activity));
        commonTypeMap.put(thisWeek, activity-> achieveService.judgeWeek(activity));
        commonTypeMap.put(thisMouth, activity-> achieveService.judgeMouth(activity));
        commonTypeMap.put(unLimited, activity-> achieveService.judgeUnLimited(activity));
        commonTypeMap.put(foreverLimit, activity-> achieveService.judgeForeverLimit(activity));
    }

    public boolean getResult(BizActivity activity,String resourceType){
        Function<BizActivity,Boolean> result = commonTypeMap.get(resourceType);
        if(StringUtils.isNotEmpty(resourceType)){
            return result.apply(activity);
        }
        return false;
    }*/
}